<cfobject type="dotnet" name="objQuery" class="ADTools.Query" assembly ="C:\Program Files\Southcentral Foundation\ADTools\ADTools.dll">  
<cfobject type="dotnet" name="objMod" class="ADTools.Modify" assembly ="C:\Program Files\Southcentral Foundation\ADTools\ADTools.dll"> 
<cfobject type="dotnet" name="objTerm" class="ADTools.Termination" assembly ="C:\Program Files\Southcentral Foundation\ADTools\ADTools.dll">



<cffunction name="funcClearErrorLog" returntype="any">
    
    <cfset LOCALS.errorLog = replace(replace(replace(replace(
            objMod.GetErrorLog(),chr(13),'<BR/>','all')
            , chr(10), '','all'),'<BR/>',''),'<BR/><BR/>','')  />
    <Cfset objMod.ClearErrorLog() />
    
    <cfreturn LOCALS.errorLog />
</cffunction>



<cffunction name="funcADDisable" returntype="numeric">
	<cfargument name="UserID" type="string" required="yes">

    <cfset objMod.init("10.100.1.101")>
    
	<cfset FUNC.Result = 0>
	
		<!--- 	
			1.  Disable Account
			2.  Scramble PW
			3.  Hide from Address List
		--->	
		
		<!--- Disable  --->
		<cfset FUNC.Result += objMod.ModifyUser(
            "#ARGUMENTS.UserID#", "userAccountControl", JavaCast("int", 514)) 
        /> 

		<!--- Scramble PW --->
		<cfset FUNC.Result += objMod.ChangePW(
            "#ARGUMENTS.UserID#", "") 
        />

		<!--- Hide from Address List --->
		<cfset FUNC.Result += objMod.ModifyUser(
            "#ARGUMENTS.UserID#", "MSExchHideFromAddressLists", JavaCast("boolean", True)) 
        />	

	<cfreturn FUNC.Result>
</cffunction>



<cffunction name="funcArchiveHomeFolder" returntype="struct">
	<cfargument name="Home" type="string" required="yes">
	<cfargument name="ArchiveDir" type="string" required="yes">
	
    <cfset FUNC = {
        Src = "",
        Dest = "",
        ArchResult ="",
        Result = 0
    } />
	
	<!--- Archive the Home Folder --->		
    <cfif DirectoryExists(Home)> 
        <cfdirectory action="list" directory="#ARGUMENTS.Home#" 
            recurse="yes" name="FUNC.Contents">
     	
        <cfloop query="FUNC.Contents">
            <cfset FUNC.Src = FUNC.Contents.Directory & "\" & 
                FUNC.Contents.Name>
            <cfset FUNC.ArchResult ="Archiving: #FUNC.Src#">
            <cfset FUNC.Dest = ARGUMENTS.ArchiveDir & "\" & 
                right(FUNC.Src, Len(FUNC.Src) - Len(ARGUMENTS.Home))
            />
            
            <cfif Type EQ "Dir">
                <cfdirectory action="create" directory="#FUNC.Dest#">
            <cfelseif Type EQ "File">
                <cffile action="copy" source="#FUNC.Src#" 
                    destination="#FUNC.Dest#" >
            </cfif>
        
        </cfloop>	 
              	
            <!--- Delete the Original --->	
            <cfdirectory action="delete" directory="#ARGUMENTS.Home#" recurse="yes">
            <cfset FUNC.ArchResult ='Archive Complete. Original directory (#ARGUMENTS.Home#) removed.'>
        
    <cfelse>
    	<cfset FUNC.ArchResult = "Directory does not exist #ARGUMENTS.Home#">
    </cfif>     
    
	<cfreturn FUNC>    
</cffunction>



<cffunction name="funcHRTerm" returntype="struct">
	<cfargument name="PersonIDNo" type="numeric" required="yes">
	<cfargument name="EmpStatusIDNo" type="numeric" required="yes">
	<cfargument name="OrgSCF" type="numeric" required="yes">
	<cfargument name="RehireElig" type="numeric" required="yes"> <!---BIT--->
	<cfargument name="TermTypeID" type="numeric" required="yes">
	<cfargument name="EmpStatusReason" type="numeric" required="yes">
	<cfargument name="ActionID" type="numeric" required="yes">
	<cfargument name="Term" type="string" required="yes">
	<cfargument name="COBRA" type="string" required="yes">

	<cfset LOCALS.SQL= "scf_SCFVM18_Termination #ARGUMENTS.PersonIDNo#, 
        #ARGUMENTS.EmpStatusIDNo#, 
        #ARGUMENTS.OrgSCF#,
        #ARGUMENTS.RehireElig#,
        #ARGUMENTS.TermTypeID#,
        #ARGUMENTS.EmpStatusReason#,
        #ARGUMENTS.ActionID#,
        '#ARGUMENTS.Term#',
        '#ARGUMENTS.COBRA#'" />
        
    <cfset thread.SQL = LOCALS.SQL>  <!---Conditional statement in case this function errors out --->
    
	<cfstoredproc datasource="#Session.DataSource#" procedure="scf_SCFVM18_Termination"> 
		<cfprocparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.PersonIDNo#>							
		<cfprocparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.EmpStatusIDNo#>
		<cfprocparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.OrgSCF#>
		<cfprocparam cfsqltype="cf_sql_bit" value=#ARGUMENTS.RehireElig#>
		<cfprocparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.TermTypeID#>
		<cfprocparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.EmpStatusReason#>
		<cfprocparam cfsqltype="cf_sql_integer" value=#ARGUMENTS.ActionID#>
		<cfprocparam cfsqltype="cf_sql_date" value="#ARGUMENTS.Term#">
		<cfprocparam cfsqltype="cf_sql_date" value="#ARGUMENTS.COBRA#">
		<cfprocresult name="Result1" resultset="1">
		<cfprocresult name="Result2" resultset="2">
		<cfprocresult name="Result3" resultset="3">
		<cfprocresult name="Result4" resultset="4">
		<cfprocresult name="ErrorCheck" resultset="5">
	</cfstoredproc>
    
	<cfset LOCALS.Result = ErrorCheck.Error>
		
	<cfreturn LOCALS />
	
</cffunction>



<cffunction name="funcDisableTimeKeeper" returntype="void">
	<cfargument name="WFCPersonID" type="numeric" required="yes">
			
	<!--- Disable TimeKeeper Record --->		
	<cfquery datasource="#Session.DataSource#" name="qryDisableTK">
		scf_SCFVM18_RenameKronosUser #ARGUMENTS.WFCPersonID#
	</cfquery>	
	
</cffunction>



<cffunction name="funcExportMailbox" returntype="struct">
	<cfargument name="UserID" type="string" required="yes">
	<cfargument name="ArchiveEmailDir" type="string" required="yes">
	<cfargument name="SERVICE_ACCOUNT" type="string" required="yes">

	<!--- Export the Mailbox --->	
	<cfset FUNC.Result = objTerm.ExportMailbox(
        "#ARGUMENTS.UserID#", 
        "#ARGUMENTS.ArchiveEmailDir#\#ARGUMENTS.UserID#.pst",
        "#ARGUMENTS.SERVICE_ACCOUNT#")>	
        
	<cfset FUNC.Error = objTerm.GetErrorText()>
	
	<cfreturn FUNC>							
</cffunction>



<cffunction name="funcArchiveAndDisable" returntype="struct">
	<cfargument name="UserID" type="string" required="yes">
	
    <cfset objMod.init("10.100.1.101")>
    
	<cfset FUNC.DN = "">
	
	<!--- Archive the Account --->	
	<cfset FUNC.DN = objQuery.GetProperty("distinguishedName", "10.100.1.101", "#ARGUMENTS.UserID#", "", "")>
	<cfset FUNC.Result = objMod.MoveToContainer("#FUNC.DN#", "#objMod.ARCHIVED_USERS_CONTAINER#")>
    <cfset FUNC.ArchivedUsersContainer = objMod.ARCHIVED_USERS_CONTAINER />
	
	<!--- Disable.  It seems during testing that the account can be enabled from time to time.  Lets make sure  --->
	<cfset FUNC.Result += objMod.ModifyUser("#ARGUMENTS.UserID#", "userAccountControl", JavaCast("int", 514))> 
	
	<cfset FUNC.Error = objMod.GetErrorLog()>
    
    <cfset FUNC.objMod = objMod />
	
	<cfreturn FUNC>	
							
</cffunction>



<cffunction name="funcDisableRosetta" returntype="void">	
	<cfargument name="RosettaID" type="string" required="yes">
	
	<!--- Disable Rosetta Record --->
	<cfquery name="qryDisableRosettaRecord" datasource="#Session.DataSourceRosetta#">
		scf_DisableRosettaUser #ARGUMENTS.RosettaID#
	</cfquery>
</cffunction>